package main

import (
	"fmt"
	"time"
)

func main() {
	c := make(chan int, 5) //设置一个带有3个缓存的channel
	fmt.Println("len(c)=", len(c), ",cap(c)", cap(c))
	go func() {
		defer fmt.Println("子go程结束")
		for i := 0; i < 3; i++ {
			c <- i
			println("子go程正在运行,发送的元素=", i, ",len(c)", len(c), ",cap(c)=", cap(c))
		}
	}()
	time.Sleep(2 * time.Second)
	num := len(c)
	for i := 0; i < num; i++ {
		println("value=", <-c, ",len(c)=", len(c))
	}
	defer fmt.Println("main结束")
}
